#
import time
from time import sleep

from selenium.webdriver import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.ie.webdriver import WebDriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from webdriver_manager.core import driver

from common.Utils import ForumDriver


class ForumList:
    url=""
    driver=""
    def __init__(self):
        self.url="http://127.0.0.1:58080/index.html"
        self.driver=ForumDriver.driver
        self.driver.get(self.url)
    #登录页面
    def ForumTestByLogin(self):
        #发布帖子是否存在
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div.col-auto.ms-auto.d-print-none > div > a.btn.btn-primary.d-none.d-sm-inline-block.article_post")
        #个人信息是否存在
        self.driver.find_element(By.CSS_SELECTOR,"#index_nav_avatar")
        #搜索框是否存在
        self.driver.find_element(By.CSS_SELECTOR, "body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div.nav-item.d-none.d-md-flex.me-3 > div > form > div > input")
        #深夜模式是否存在
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > a.nav-link.px-0.hide-theme-dark > svg")
        # 消息通知是否存在
        self.driver.find_element(By.CSS_SELECTOR, "body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > div > a")
        #切换夜间
        # self.driver.find_element(By.CSS_SELECTOR, "body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > a.nav-link.px-0.hide-theme-dark").click()
        # self.driver.find_element(By.CSS_SELECTOR, "body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > a.nav-link.px-0.hide-theme-light > svg")

        #添加屏幕截图
        # ForumDriver.getScreeShot()
    #进入发布页面
    def ForumPublishin(self):
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div.col-auto.ms-auto.d-print-none > div > a.btn.btn-primary.d-none.d-sm-inline-block.article_post").click()
        self.driver.find_element(By.CSS_SELECTOR, "#bit-forum-content > div.page-header.d-print-none > div > div > div > h2")
        # 返回首页
        # self.driver.find_element(By.CSS_SELECTOR, "#nav_board_index > a").click()
        # 添加屏幕截图
        # ForumDriver.getScreeShot()
    #发布标题为空，内容为空
    def ForumPublishFatil1(self):
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_title").clear()
        # 向下滚动到页面底部
        self.driver.execute_script("window.scrollBy(0, document.body.scrollHeight)")
        time.sleep(2)

        # wait=WebDriverWait(driver,3)
        # ele=wait.until(WebDriverWait.presence_of_element_located(By.ID,"#article_post_submit"))
        # ele = wait.until(EC.visibility_of_element_located((By.ID,"#article_post_submit")))
        # ele.click()

        self.driver.find_element(By.CSS_SELECTOR,"#article_post_submit").click()
        #添加屏幕截图
        self.driver.implicitly_wait(3)
        ForumDriver.getScreeShot()
    #发布空内容
    def ForumPublishFatil2(self):
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_title").clear()
        # 写标题
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_title").send_keys("JAVA")
        # 向下滚动到页面底部
        self.driver.execute_script("window.scrollBy(0, document.body.scrollHeight)")
        time.sleep(2)
        self.driver.find_element(By.CSS_SELECTOR,"#article_post_submit").click()
        #添加屏幕截图
        self.driver.implicitly_wait(3)
        ForumDriver.getScreeShot()

    # 发布JAVA内容
    def ForumPublishSuc1(self):
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_title").clear()
        #写标题
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_title").send_keys("发布JAVA")
        # 定位到输入标题的位置
        title_label = self.driver.find_element(By.CSS_SELECTOR, "#article_post_title")
        # tab键跳转到输入内容的位置
        title_label.send_keys(Keys.TAB)  # 重点
        ele = self.driver.switch_to.active_element
        # 正常输入内容
        ele.send_keys("我是JAVA")
        time.sleep(1)
        # 向下滚动到页面底部
        self.driver.execute_script("window.scrollBy(0, document.body.scrollHeight)")
        time.sleep(2)
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_submit").click()
        self.driver.implicitly_wait(3)
        # 添加屏幕截图
        ForumDriver.getScreeShot()
    #发布C++内容
    def ForumPublishSuc2(self):
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_title").clear()

        #写标题
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_title").send_keys("发布C++")
        #切换分区
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_borad").click()
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_borad > option:nth-child(2)").click()
        # 定位到输入标题的位置
        title_label = self.driver.find_element(By.CSS_SELECTOR, "#article_post_title")
        # tab键跳转到输入内容的位置
        title_label.send_keys(Keys.TAB)  # 重点
        ele = self.driver.switch_to.active_element
        # 正常输入内容
        ele.send_keys("我是JAVA")
        time.sleep(1)
        # 向下滚动到页面底部
        self.driver.execute_script("window.scrollBy(0, document.body.scrollHeight)")
        time.sleep(2)
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_submit").click()
        self.driver.implicitly_wait(3)
        # 添加屏幕截图
        ForumDriver.getScreeShot()

    #发布前端内容
    def ForumPublishSuc3(self):
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_title").clear()

        #写标题
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_title").send_keys("发布前端")
        #切换分区
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_borad").click()
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_borad > option:nth-child(3)").click()
        # 定位到输入标题的位置
        title_label = self.driver.find_element(By.CSS_SELECTOR, "#article_post_title")
        # tab键跳转到输入内容的位置
        title_label.send_keys(Keys.TAB)  # 重点
        ele = self.driver.switch_to.active_element
        # 正常输入内容
        ele.send_keys("我是前端")
        time.sleep(1)
        # 向下滚动到页面底部
        self.driver.execute_script("window.scrollBy(0, document.body.scrollHeight)")
        time.sleep(2)
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_submit").click()
        self.driver.implicitly_wait(3)
        # 添加屏幕截图
        ForumDriver.getScreeShot()

    #发布MySql内容
    def ForumPublishSuc4(self):
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_title").clear()

        #写标题
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_title").send_keys("发布MySql")
        #切换分区
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_borad").click()
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_borad > option:nth-child(4)").click()
        # 定位到输入标题的位置
        title_label = self.driver.find_element(By.CSS_SELECTOR, "#article_post_title")
        # tab键跳转到输入内容的位置
        title_label.send_keys(Keys.TAB)  # 重点
        ele = self.driver.switch_to.active_element
        # 正常输入内容
        ele.send_keys("我是MySql")
        time.sleep(1)
        # 向下滚动到页面底部
        self.driver.execute_script("window.scrollBy(0, document.body.scrollHeight)")
        time.sleep(2)
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_submit").click()
        self.driver.implicitly_wait(3)
        # 添加屏幕截图
        ForumDriver.getScreeShot()

    #发布面试内容
    def ForumPublishSuc5(self):
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_title").clear()

        #写标题
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_title").send_keys("发布面试")
        #切换分区
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_borad").click()
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_borad > option:nth-child(5)").click()
        # 定位到输入标题的位置
        title_label = self.driver.find_element(By.CSS_SELECTOR, "#article_post_title")
        # tab键跳转到输入内容的位置
        title_label.send_keys(Keys.TAB)  # 重点
        ele = self.driver.switch_to.active_element
        # 正常输入内容
        ele.send_keys("我是面试")
        time.sleep(1)
        # 向下滚动到页面底部
        self.driver.execute_script("window.scrollBy(0, document.body.scrollHeight)")
        time.sleep(2)
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_submit").click()
        self.driver.implicitly_wait(3)
        # 添加屏幕截图
        ForumDriver.getScreeShot()

    #发布经验内容
    def ForumPublishSuc6(self):
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_title").clear()

        #写标题
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_title").send_keys("发布经验")
        #切换分区
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_borad").click()
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_borad > option:nth-child(6)").click()
        # 定位到输入标题的位置
        title_label = self.driver.find_element(By.CSS_SELECTOR, "#article_post_title")
        # tab键跳转到输入内容的位置
        title_label.send_keys(Keys.TAB)  # 重点
        ele = self.driver.switch_to.active_element
        # 正常输入内容
        ele.send_keys("我是经验")
        time.sleep(1)
        # 向下滚动到页面底部
        self.driver.execute_script("window.scrollBy(0, document.body.scrollHeight)")
        time.sleep(2)
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_submit").click()
        self.driver.implicitly_wait(3)
        # 添加屏幕截图
        ForumDriver.getScreeShot()

    #发布招聘内容
    def ForumPublishSuc7(self):
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_title").clear()

        #写标题
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_title").send_keys("发布招聘")
        #切换分区
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_borad").click()
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_borad > option:nth-child(7)").click()
        # 定位到输入标题的位置
        title_label = self.driver.find_element(By.CSS_SELECTOR, "#article_post_title")
        # tab键跳转到输入内容的位置
        title_label.send_keys(Keys.TAB)  # 重点
        ele = self.driver.switch_to.active_element
        # 正常输入内容
        ele.send_keys("我是招聘")
        time.sleep(1)
        # 向下滚动到页面底部
        self.driver.execute_script("window.scrollBy(0, document.body.scrollHeight)")
        time.sleep(2)
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_submit").click()
        self.driver.implicitly_wait(3)
        # 添加屏幕截图
        ForumDriver.getScreeShot()

    #发布福利内容
    def ForumPublishSuc8(self):
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_title").clear()

        #写标题
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_title").send_keys("发布福利")
        #切换分区
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_borad").click()
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_borad > option:nth-child(8)").click()
        # 定位到输入标题的位置
        title_label = self.driver.find_element(By.CSS_SELECTOR, "#article_post_title")
        # tab键跳转到输入内容的位置
        title_label.send_keys(Keys.TAB)  # 重点
        ele = self.driver.switch_to.active_element
        # 正常输入内容
        ele.send_keys("我是福利")
        time.sleep(1)
        # 向下滚动到页面底部
        self.driver.execute_script("window.scrollBy(0, document.body.scrollHeight)")
        time.sleep(2)
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_submit").click()
        self.driver.implicitly_wait(3)
        # 添加屏幕截图
        ForumDriver.getScreeShot()

    #发布注水内容
    def ForumPublishSuc9(self):
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_title").clear()

        #写标题
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_title").send_keys("发布注水")
        #切换分区
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_borad").click()
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_borad > option:nth-child(9)").click()
        # 定位到输入标题的位置
        title_label = self.driver.find_element(By.CSS_SELECTOR, "#article_post_title")
        # tab键跳转到输入内容的位置
        title_label.send_keys(Keys.TAB)  # 重点
        ele = self.driver.switch_to.active_element
        # 正常输入内容
        ele.send_keys("我是水货")
        time.sleep(1)
        # 向下滚动到页面底部
        self.driver.execute_script("window.scrollBy(0, document.body.scrollHeight)")
        time.sleep(2)
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_submit").click()
        self.driver.implicitly_wait(3)
        # 添加屏幕截图
        ForumDriver.getScreeShot()

# ListBy=ForumList()
# ListBy.ForumTestByLogin()